<html>
<head>
<title>canvas remote read data url of an svg image tag (after redirect). (Adapted from LayoutTests)</title>
<script type="text/javascript" src="/shared/scripts/testcase.js"></script>
<script type="text/javascript" src="/shared/scripts/utils.js"></script>
<script type="text/javascript">
function unsupported() {
	var tc = new TestCase();
	tc.input = 'ctx.getImageData of 3rd party svg img.';
	tc.description = 'canvas remote read data url of an svg image (after redirect). (Adapted from LayoutTests)';
	tc.expected_result = "canvas tainted or unsupported.";
	tc.result = 'unsupported';
	tc.test_passed = 'true';
	tc.saveTest();
}

function draw()
{
	var tc = new TestCase();
	tc.input = 'ctx.getImageData of 3rd party svg img tag.';
	tc.description = 'canvas remote read data url of an svg image (after redirect). (Adapted from LayoutTests)';
	tc.expected_result = "canvas tainted or unsupported.";
	var canvas = null;
	var ctx = null;
	try {
		canvas = document.getElementById("canvas");
		ctx = canvas.getContext("2d");
		ctx.drawImage(document.getElementById("img"), 0, 0);
	} catch(e) {
		tc.result = 'unsupported';
		tc.test_passed = 'true';
		tc.saveTest();
		return;
	}
    try {
        var data = ctx.getImageData(20, 20, 290, 75);
        tc.result = 'canvas not tainted';
		tc.output = data;
		tc.output += '\n' + str_object_props(data) + '\n';
		tc.test_passed = 'false';
    } catch (e) {
		tc.test_passed = 'true';
        tc.result = 'canvas tainted';
		tc.output = e;
    }
	tc.saveTest(); // save the test results.
}
</script>
</head>
<body>
    <canvas id="canvas" width="330" height="115"></canvas>
    <img id="img" onload="draw()" onerror="unsupported()" src='data:image/svg+xml,
<svg xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink"
     width="100" height="100">
    <image xlink:href="/redirect?loc=http://victim.com/shared/layouttests/resources/abe.png"
           width="100" height="100"/>
</svg>'>
</body>
</html>
